package org.example.simplemanagementsystem.controller;

import org.example.simplemanagementsystem.pojo.*;
import org.example.simplemanagementsystem.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;

    /**
     * 分页查询
     * @param studentQueryParam
     * @return
     */
    @GetMapping
    public Result page(StudentQueryParam studentQueryParam) {
        PageResult pageResult = studentService.page(studentQueryParam);
        return Result.success(pageResult);
    }

    /**
     * 添加员工
     */
    @PostMapping
    public Result add(@RequestBody Student student) {
        studentService.save(student);
        return Result.success();
    }

    /**
     * 根据id获取学生信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getInfoById(@PathVariable Integer id) {
        Student student = studentService.getInfoById(id);
        return Result.success(student);
    }

    /**
     * 根据id更新学生的处罚信息
     * @param id
     * @param score
     * @return
     */
    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable Integer id, @PathVariable Integer score) {
        // 根据id获取学员信息
        studentService.violation(id, score);
        return Result.success();
    }

    /**
     * 编辑修改学生数据
     * @param student
     * @return
     */
    @PutMapping
    public Result update(@RequestBody Student student) {
        studentService.update(student);
        return Result.success();
    }

    /**
     * 根据 id删除学员信息
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids) {
        studentService.delete(ids);
        return Result.success();
    }
}
